<%@ page language="java" import="java.util.Map,org.json.*,java.sql.*,com.microsoft.sqlserver.jdbc.*,java.io.*,web.rec.*" 
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"  %>

<% 
	ResourceTool.init();
	String form = request.getParameter("form");
	if(form!=null)
		ResourceTool.setForm(form);
	else{
		response.sendRedirect("mainPage.jsp");
		return;
	}

	String action = request.getParameter("action");
	if(action != null ){
		if(action.equals("insert"))
			ResourceTool.insertDB(request);
		else if(action.equals("update") || action.equals("delete"))
			ResourceTool.modifyDB(request,action);  
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="script/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="script/form_script.js"></script>
<link rel="stylesheet" type="text/css" href="style/mainstyle.css" />

<style type="text/css" >

</style>
</head>
<body>
<div>
<div id="menu">
<div><a href="mainPage.jsp">Main Page</a></div><br />
	<%
		Map<String,String[]> map = ResourceTool.menuMap;
		String popup = request.getParameter("popup");
		
		if(popup == null || popup.equals("false")){
		
			for(String key: map.keySet()){
		%>
		<div>
			<h3><%= key %></h3>
			<%= ResourceTool.getMenu(key) %>
		</div><br />
		<%
			}
		}
	%>
</div>

<div id="content">
<h1><%= form %></h1><div id='queryError'><%= ResourceTool.getErrorString() %></div>
<form method="get" action="formspage.jsp" >
	<!-- <table id="input_table"> -->
	<div id="input_div">
			<%
			
				//ResourceTool.buildInputForm(request, out );
				ResourceTool.buildInput(request, out );
				
			%>
			<div id="input_buttons">
				<input type="submit" value="insert" />
				<button type='button' onclick='window.open(updateFields("<%= ResourceTool.formName %>"),"_self");return false;'>update</button>
				<button type='button' onclick='clearFields();return false;'>clear</button>
			</div>
	</div>
	<!-- </table> -->
	<!-- <table id="output_table"> -->
	<div id='output_group'>
		<%
			ResourceTool.buildOutputRows(out);
		%>
	</div>
	<!-- </table> -->
	
	<input type="hidden" name="form" id="form_action" value="<%=form %>" />
	<input type="hidden" name="action" id="form_action" value="insert" />
</form>

</div>
</div>

</body>
</html>

